use std::io;
use std::fs;
use std::path::Path;
use colored::*;
struct FileInfo {
    file_name: String,
    file_type: String,
    file_create_time: String,
}

fn main() -> io::Result<()> {
    let mut dir_vec: Vec<FileInfo> = Vec::new();
    let mut file_vec: Vec<FileInfo> = Vec::new();
    for entry in fs::read_dir(Path::new("."))? {
        let dir_entry = entry?;
        let path = dir_entry.path();
        let file_name: String = path.file_name().unwrap().to_str().map(String::from).unwrap();
        
        let is_file = dir_entry.file_type()?.is_file();
        let file_type = if is_file { "<File>" } else { "<Dir>" };
        let datetime: chrono::DateTime<chrono::Local> = fs::metadata(dir_entry.path())?.created()?.into();
        let create_datetime = datetime.format("%y/%m/%d %H:%M:%S");
        let file_info = FileInfo {
            file_name: file_name.to_string(),
            file_type: file_type.to_string(),
            file_create_time: create_datetime.to_string(),
        };
        if is_file {
            file_vec.push(file_info);
        } else {
            dir_vec.push(file_info);
        }
    }

    for info in dir_vec {
        println!("{0}\t{1}\t\t{2}", info.file_create_time.yellow(), info.file_type.green(), info.file_name);
    }
    for info in file_vec {
        println!("{0}\t{1}\t\t{2}", info.file_create_time.yellow(), info.file_type.blue(), info.file_name);
    }

    Ok(())
}
